package com.getpebble.android.framework.protocol.outbound;

import com.getpebble.android.framework.protocol.EndpointId;
import com.getpebble.android.framework.util.ByteUtils;
import com.google.common.primitives.UnsignedInteger;
import com.sun.mail.imap.protocol.ListInfo;
import com.sun.mail.smtp.SMTPMessage;
import java.util.Iterator;
import java.util.List;

public class PblOutboundDataloggingMessage extends PblOutboundMessage {
    private Command mCommand;
    private UnsignedInteger mSessionId;
    private List<UnsignedInteger> mSessionIds;

    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundDataloggingMessage$Command = new int[Command.values().length];

        static {
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundDataloggingMessage$Command[Command.REPORT_OPEN_SESSIONS.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundDataloggingMessage$Command[Command.ACK.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundDataloggingMessage$Command[Command.NACK.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
        }
    }

    public enum Command {
        REPORT_OPEN_SESSIONS((byte) -124),
        ACK((byte) -123),
        NACK((byte) -122),
        UNKNOWN((byte) -1);
        
        private byte command;

        private Command(byte command) {
            this.command = command;
        }

        public byte getCommand() {
            return this.command;
        }
    }

    private PblOutboundDataloggingMessage(Command command) {
        super(EndpointId.DATA_LOG);
        this.mCommand = command;
    }

    public static PblOutboundDataloggingMessage createReportOpenSessionsMessage(List<UnsignedInteger> sessionIds) {
        PblOutboundDataloggingMessage message = new PblOutboundDataloggingMessage(Command.REPORT_OPEN_SESSIONS);
        message.mSessionIds = sessionIds;
        return message;
    }

    public static PblOutboundDataloggingMessage createAckMessage(UnsignedInteger sessionId) {
        PblOutboundDataloggingMessage message = new PblOutboundDataloggingMessage(Command.ACK);
        message.mSessionId = sessionId;
        return message;
    }

    public static PblOutboundDataloggingMessage createNackMessage(UnsignedInteger sessionId) {
        PblOutboundDataloggingMessage message = new PblOutboundDataloggingMessage(Command.NACK);
        message.mSessionId = sessionId;
        return message;
    }

    public synchronized byte[] getBytes() {
        if (!areBytesCached()) {
            addBytes(Byte.valueOf(this.mCommand.getCommand()));
            switch (AnonymousClass1.$SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundDataloggingMessage$Command[this.mCommand.ordinal()]) {
                case SMTPMessage.RETURN_FULL /*1*/:
                    Iterator i$ = this.mSessionIds.iterator();
                    while (i$.hasNext()) {
                        addBytes(Byte.valueOf(ByteUtils.unsignedInt2byte((UnsignedInteger) i$.next())));
                    }
                    break;
                case SMTPMessage.RETURN_HDRS /*2*/:
                case ListInfo.INDETERMINATE /*3*/:
                    addBytes(Byte.valueOf(ByteUtils.unsignedInt2byte(this.mSessionId)));
                    break;
            }
        }
        return super.getBytes();
    }
}
